package com.ck.ips.core.config;

import com.ck.ips.core.spring.CustomConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import javax.annotation.PostConstruct;

/**
* @Description: 使用自定义的转换器处理参数
* @Author: hf
* @Date:    2019/4/29 16:01
* @Version: 1.0
*/
@Configuration
public class RequestParamsConvert {
	@Autowired
	private RequestMappingHandlerAdapter requestMappingHandlerAdapter;

	@PostConstruct
	public void addConversionConfig(){
		ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) requestMappingHandlerAdapter.getWebBindingInitializer();
		if(initializer.getConversionService()!=null){
			GenericConversionService genericConversionService =(GenericConversionService) initializer.getConversionService();
			genericConversionService.addConverter(new CustomConverter());
		}
	}
}

